//
//  UIColor+Extension.swift
//  MT
//
//  Created by zhang qiang on 2018/11/21.
//  Copyright © 2019年 张强. All rights reserved.
//

import UIKit

public extension UIColor {
    
    /// 随机色
    static var random: UIColor {
        let maxValue: UInt32 = 24
        return UIColor(red: CGFloat(arc4random() % maxValue) / CGFloat(maxValue),
                       green: CGFloat(arc4random() % maxValue) / CGFloat(maxValue) ,
                       blue: CGFloat(arc4random() % maxValue) / CGFloat(maxValue) ,
                       alpha: 1)
    }
    
    
    /// 便利构造函数
    ///
    /// - Parameters:
    ///   - red: red
    ///   - green: green
    ///   - blue: blue
    convenience init(red: Int, green: Int, blue: Int) {
        assert(red >= 0 && red <= 255, "Invalid red component")
        assert(green >= 0 && green <= 255, "Invalid green component")
        assert(blue >= 0 && blue <= 255, "Invalid blue component")
        
        self.init(red: CGFloat(red) / 255.0, green: CGFloat(green) / 255.0, blue: CGFloat(blue) / 255.0, alpha: 1.0)
    }
    
    
    /// 十六进制颜色 - 可设置透明度
    ///
    /// - Parameters:
    ///   - hex: 十六进制
    ///   - alpha: 透明度
    convenience init(hex: Int, alpha: Float) {
        self.init(
            red: CGFloat((hex & 0xFF0000) >> 16) / 255.0,
            green: CGFloat((hex & 0x00FF00) >> 8) / 255.0,
            blue: CGFloat(hex & 0x0000FF) / 255.0,
            alpha: CGFloat.init(alpha)
        )
    }
    
    /// 十六进制颜色
    ///
    /// - Parameters:
    ///   - hex: 十六进制
    convenience init(hex:Int) {
        self.init(hex: hex, alpha: 1)
    }
    
}

// MARK: ------------------ 自定义颜色 ----------------------
public extension UIColor {
    
    /// 主题
    struct theme {
        
        /// App 主题颜色
        public static var main:                 UIColor { return UIColor(hex: 0xffc000) }
        
        /// 背景主题颜色
        public static var background:           UIColor { return UIColor(hex: 0xffffff) }
        
    }
    
    /// 聊天消息
    struct chat {
        /// 红点背景色
        public static var xff003d:              UIColor { return UIColor(hex: 0xff003d) }
    }
    
    /// 字体颜色
    struct text {
        
        /// 1d1a1a 颜色
        public static var x1d1a1a:              UIColor { return UIColor(hex: 0x1d1a1a) }
        
        /// f3f3f3
        public static var xf3f3f3:              UIColor { return UIColor(hex: 0xf3f3f3) }
        
        /// x#161616
        public static var x161616:              UIColor { return UIColor(hex: 0x161616) }
        
        /// x333333
        public static var x333333:              UIColor { return UIColor(hex: 0x333333) }
        
        /// xfed600
        public static var xfed600:              UIColor { return UIColor(hex: 0xfed600) }
        
        /// x9f9f9f
        public static var x999999:              UIColor { return UIColor(hex: 0x999999) }
        
        /// x9b9b9b
        public static var x9b9b9b:              UIColor { return UIColor(hex: 0x9b9b9b) }
        
    }
    
    ///
    struct common {
        
        /// 161616 颜色
        public static var x161616:              UIColor { return UIColor(hex: 0x161616) }
        
    }
    
    /// IM列表颜色
    struct im {
        public static var x1d1a1a:              UIColor { return UIColor(hex: 0x1D1A1A) }
        
        public static var xfd387c:              UIColor { return UIColor(hex: 0xfd387c) }
    }
    
    /// 红包相关颜色
    struct redpack {
        /// 按钮禁用颜色
        public static var x5d5d5d:              UIColor { return UIColor(hex: 0x5d5d5d) }
        
        /// xEF1E66 - 红包上方形状的颜色
        public static var xef1e66:              UIColor { return UIColor(hex: 0xef1e66) }
    }
    
    /// 分割线颜色
    struct seprateLine {
        /// x707070
        public static var x707070:              UIColor { return UIColor(hex: 0xe6e6e6) }
    }
    
}

